package com.qqhf.hitfood.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qqhf.common.entity.AjaxResult;
import com.qqhf.common.entity.PageEntity;
import com.qqhf.hitfood.bean.core.BaseController;
import com.qqhf.hitfood.bean.entity.AcctRole;
import com.qqhf.hitfood.service.IAcctRoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Api(tags = "A - [字典]账号权限")
@RestController
@RequestMapping("/acct/role")
public class AcctRoleController extends BaseController {
    @Autowired
    private IAcctRoleService acctRoleService;

    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity, AcctRole acctRole) {
        return AjaxResult.success(acctRoleService.page(pageEntity.toPage(), Wrappers.lambdaQuery(acctRole)));
    }

    @GetMapping("/list")
    public AjaxResult list(AcctRole acctRole) {
        return AjaxResult.success(acctRoleService.list(Wrappers.lambdaQuery(acctRole)));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody AcctRole acctRole) {
        return AjaxResult.success(acctRoleService.save(acctRole));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody AcctRole acctRole) {
        return AjaxResult.success(acctRoleService.updateById(acctRole));
    }

    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(acctRoleService.removeByIds(Arrays.asList(ids)));
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(acctRoleService.getById(id));
    }
}
